package com.example.main;

import models.Main_model;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

	private Main_model model = new Main_model();

	@SuppressLint("ShowToast")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		model.get_datas(this);
		((TextView) findViewById(R.id.textView1)).setText(model.getText());

		((Button) findViewById(R.id.button1))
				.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {

						((TextView) findViewById(R.id.textView1))
								.setText("Merge");
					}
				});
		((Button) findViewById(R.id.button2))
		.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				((TextView) findViewById(R.id.textView1))
						.setText("Merge2");
			}
		});
		
		model.get_datas(this);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);

		model.get_datas(this);
		((TextView) findViewById(R.id.textView1)).setText(model.getText());

	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);

		model.setText(((TextView) findViewById(R.id.textView1)).getText().toString());
		model.put_datas(this);
		

	}

}
